package com.cwits.wifi.wxapi;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.cwits.wifi.R;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

/**
 * Created by Administrator on 2016-04-15.
 */
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {


    private static final String APP_ID = "wx25f4c929710a4976";
    private IWXAPI api;

    @Override
    public void onReq(BaseReq baseReq) {
        int result = 0;
        switch (baseReq.getType()) {
            case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
                result = 1;
                break;
            case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
                result = 2;
                break;
            default:
                break;

        }
        Toast.makeText(this, result + "=req", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onResp(BaseResp baseResp) {

        int result = 0;

        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                result = R.string.errcode_success;
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                result = R.string.errcode_cancel;
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                result = R.string.errcode_deny;
                break;
            default:
                result = R.string.errcode_unknown;
                break;
        }
        Toast.makeText(this, result, Toast.LENGTH_LONG).show();
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, APP_ID, true);
        api.registerApp(APP_ID);
        api.handleIntent(this.getIntent(), this);
    }
}
